<template>
	<loading-page v-if="data.loading" />
	<web-view v-if="data.webview.show" :src="data.webview.src"></web-view>
</template>
<script setup>
	import { reactive } from 'vue';
	import { useStore } from 'vuex';
	import { onLoad } from '@dcloudio/uni-app';
	import config from '@/uni.config.js';
	import { tongji } from '@/common/api/common/tongji.js';
	const store = useStore();
	onLoad((options) => {
		data.options = options;
		init();
	});
	const token = store.getters.token;
	const defaultTarget = {
		message: 'pages/message/message',
		chat: 'pages/chat/chat'
	}
	const data = reactive({
		options: {},
		loading: true,
		webview: {
			src: url,
			show: false
		},
		target: defaultTarget.message
	})
	let url = `${config.host.openapi}/html/chat/index#/${data.target}?platform=crm&token=${token}`;
	// 初始化
	function init() {
		data.target = defaultTarget.message;
		if (data.options.conversationID) {
			data.target = defaultTarget.chat;
			url = `${config.host.openapi}/html/chat/index#/${data.target}?platform=crm&token=${token}`;
			url += `&conversationID=${data.options.conversationID}`;
		};
		if (data.options.nick) url += `&nick=${data.options.nick}`;
		if (data.options.goodsInfo) url += `&goodsInfo=${data.options.goodsInfo}`;
		data.webview.src = url;
		setTimeout(() => {
			data.webview.show = true;
			tongji({ type: 'im', merchant_mid: data.options.conversationID });
		}, 100)
	}
</script>
